<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class DemoEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($test)
    {
        //
        $this->message = $test;
    }

    // 广播频道
    public function broadcastOn()
    {
//        var_dump('broadcastOn');
        // return new PrivateChannel('channel-name');
        return new Channel('test_public_channel');
    }

    // 广播内容
    public function broadcastWith()
    {
//        var_dump('broadcastWith');
        return ['message'=> $this->message];
    }

    // 广播事件名称，默认为 App\Events\TestEvent
    public function broadcastAs()
    {
        return 'TestEvent';
    }

    // 决定是否广播的条件
//    public function broadcastWhen()
//    {
//        if ('test') {
//            return true;
//        }
//    }

}
